<?php

namespace maotool\src\test;

use maotool\file\DirUtil;
use maotool\log\Console;
use maotool\util\ImageUtil;
use maotool\util\PhpUtil;
use PHPUnit\Framework\TestCase;

class ImageUtilTest extends TestCase
{

    public function testCompress()
    {
        ImageUtil::compress("F:/Downloads/*", 1);
        $lines = Console::$lines;
        foreach ($lines as $line) {
            echo json_encode($line["ages"], JSON_UNESCAPED_UNICODE) . "\n";
        }
        $this->assertTrue(true);
    }

    public function testResize()
    {
        ImageUtil::resize("F:/Downloads/王良01(1).jpg", 300, 300);
//        ImageUtil::resize("F:/Downloads/王良01(1).jpg", "500max");
//        ImageUtil::resize("F:/Downloads/*", "80%");
//        ImageUtil::resize("F:/Downloads/*", "200min");
//        ImageUtil::resize("F:/Downloads/*", "200min");
        $this->assertTrue(true);
    }

    public function testDemo1()
    {
        $files = DirUtil::scanFiles("F:/Downloads/*");
        foreach ($files as $file) {
            if (ImageUtil::isImage($file['path'])) {
                if (ImageUtil::isSquare($file['path'])) {
                    ImageUtil::resize($file['path'], "500max");
                } else if (ImageUtil::isVertical($file['path'])) {
                    ImageUtil::resize($file['path'], null, "1000max");
                } else if (ImageUtil::isHorizontal($file['path'])) {
                    if (ImageUtil::isNarrow($file['path'])) {
                        ImageUtil::resize($file['path'], "300max");
                    } else {
                        ImageUtil::resize($file['path'], "1000max");
                    }
                }
                ImageUtil::compress($file['path'], 70);
            }
        }
        $this->assertTrue(true);
    }

}